package com.java110.fee.dao.impl;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.ecs.transform.v20140526.RemoveTagsResponseUnmarshaller;
import com.java110.core.base.dao.BaseServiceDao;
import com.java110.core.log.LoggerFactory;
import com.java110.fee.dao.IChequeServiceDao;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.DAOException;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("chequeServiceDaoImpl")
public class ChequeServiceDaoImpl extends BaseServiceDao implements IChequeServiceDao  {

    private static Logger logger = LoggerFactory.getLogger(ChequeServiceDaoImpl.class);

    /**
     * 保存票据管信息
     * @param info
     * @throws DAOException
     */
    @Override
    public int saveChequeInfo(Map info) throws DAOException {
        logger.debug("保存票据管理信息Instance 入参 info : {}",info);
        int saveFlag = sqlSessionTemplate.insert("chequeServiceDaoImpl.saveChequeInfo",info);

        if(saveFlag < 1){
            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存票据管理信息Instance数据失败："+ JSONObject.toJSONString(info));
        }
        return saveFlag;
    }

    @Override
    public List<Map> getChequeInfo(Map info) throws DAOException {
        logger.debug("查询票据管理信息 入参 info : {}",info);

        List<Map> chequeInfo = sqlSessionTemplate.selectList("chequeServiceDaoImpl.getChequeInfo",info);

        return chequeInfo;
    }

    @Override
    public int updateChequeInfo(Map info) throws DAOException {
        logger.debug("修改票据管理信息Instance 入参 info : {}",info);

        int saveFlag = sqlSessionTemplate.update("chequeServiceDaoImpl.updateChequeInfo",info);

        if(saveFlag < 1){
            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改票据管理信息Instance数据失败："+ JSONObject.toJSONString(info));
        }
        return  saveFlag;
    }

    @Override
    public int queryChequeCount(Map info) {
        logger.debug("查询票据管理数据 入参 info : {}",info);

        List<Map> chequeInfo = sqlSessionTemplate.selectList("chequeServiceDaoImpl.queryChequeCount", info);
        if (chequeInfo.size() < 1) {
            return 0;
        }

        return Integer.parseInt(chequeInfo.get(0).get("count").toString());
    }

}
